import { NoFlags, Placement, isFn, isStrOrNum, isUndefined } from '../shared/utils';
import {
  HostComponent,
  ClassComponent,
  FunctionComponent,
  Fragment,
  HostText,
} from './ReactWorkTags';

function createFiber(vNode, returnFiber) {
  const fiber = {
    type: vNode.type,
    key: null,
    stateNode: null,
    return: returnFiber,
    child: null,
    sibling: null,
    index: 0,
    flags: Placement,
    props: vNode.props,
    alternate: null,
    updateQueue: null,
    memorizedState: null,
  };
  if (isStrOrNum(fiber.type)) {
    fiber.tag = HostComponent;
  } else if (isFn(fiber.type)) {
    fiber.tag = fiber.type.prototype.isReactComponent
      ? ClassComponent
      : FunctionComponent;
  } else if (isUndefined(fiber.type)) {
    fiber.tag = HostText;
    fiber.props = {
      children: vNode,
    };
  } else {
    fiber.tag = Fragment;
  }
  return fiber;
}

export default createFiber;
